/******************************************************************************
 * PROPRIETARY/CONFIDENTIAL 
 * Copyright (c) 2014 QuantGroup 
 * 
 * All rights reserved. This medium contains confidential and proprietary 
 * source code and other information which is the exclusive property of 
 * QuantGroup. None of these materials may be used, disclosed, transcribed, 
 * stored in a retrieval system, translated into any other language or other
 * computer language, or transmitted in any form or by any means (electronic,
 * mechanical, photocopied, recorded or otherwise) without the prior written 
 * permission of QuantGroup. 
 *******************************************************************************/
package com.v1.video.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
/**
 * 
 * @author wangfang
 *
 */
public class PreferencesUtils {

	private Editor editor;
	private SharedPreferences sp;
	private static PreferencesUtils mPu = null;

	/**
	 * 不包含文件名，取默认配置文件
	 */
	private PreferencesUtils(Context context) {
		sp = PreferenceManager.getDefaultSharedPreferences(context);
		editor = sp.edit();
	}

	public static PreferencesUtils getInstance(Context context) {
		if (mPu == null) {
			mPu = new PreferencesUtils(context);
		}
		return mPu;
	}

	public boolean getBoolean(String key, boolean defValue) {
		return sp.getBoolean(key, defValue);
	}

	public void putBoolean(String key, boolean state) {
		editor.putBoolean(key, state);
		editor.commit();
	}

	public String getString(String key, String defValue) {
		return sp.getString(key, defValue);
	}

	public void putString(String key, String value) {
		editor.putString(key, value);
		editor.commit();
	}

	public int getInt(String key, int defValue) {
		return sp.getInt(key, defValue);
	}

	public void putInt(String key, int value) {
		editor.putInt(key, value);
		editor.commit();
	}

	public void putLong(String key, long value) {
		editor.putLong(key, value);
		editor.commit();
	}

	public long getLong(String key, long defValue) {
		return sp.getLong(key, defValue);
	}

	public boolean contains(String key) {
		return sp.contains(key);
	}

	public void remove(String key) {
		editor.remove(key);
		editor.commit();
	}

	public void clear() {
		editor.clear();
		editor.commit();
	}

	
}